package cn.itsource.pet.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.pet.domain.SearchMasterMessage;
import cn.itsource.pet.query.SearchMasterMessageQuery;
import cn.itsource.pet.service.ISearchMasterMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 宠物审核类
 */
@RestController
@Api(tags = "宠物审核类", description = "宠物审核类")
@RequestMapping("/searchMasterMessage")
public class SearchMasterMessageController {

    @Autowired
    private ISearchMasterMessageService searchMasterMessageService;

    /**
     * 发布寻主需求
     * @param message
     * @return
     */
    @PostMapping("/publish")
    public AjaxResult publish(@RequestBody @Valid SearchMasterMessage message){

        //调用业务
        return searchMasterMessageService.publish(message);
    }
    @PostMapping("/shenghe")
    public AjaxResult shengHe(@RequestBody SearchMasterMessage message){

        //调用业务
        return searchMasterMessageService.shengHe(message);
    }



    /**
     * 查询所有
     * @return 员工列表
     */
    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有员工",notes = "可以查询所有的员工")
    public AjaxResult findAll(){
        return AjaxResult.createSuccess(searchMasterMessageService.findAll());
    }


    /**
     * 分页查询
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation(value = "分页查询",notes = "可以分页查询所有的员工")
    public AjaxResult findPage(@RequestBody SearchMasterMessageQuery query){
        return AjaxResult.createSuccess(searchMasterMessageService.findPage(query));
    }

    /**
     * 新增或者修改,根据id区分
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增修改",notes = "可以根据id区分操作")
    public AjaxResult saveOrUpdate(@RequestBody SearchMasterMessage searchMasterMessage){

        //根据id区分,没有id就是新增
        try {
            searchMasterMessageService.saveOrUpdate(searchMasterMessage);

            return AjaxResult.createSuccess();
        } catch (Exception e) {

            e.printStackTrace();
            return AjaxResult.createError("操作异常,联系管理员李裕");
        }
    }

    /**
     * 删除员工根据id
     * @return
     * 接受请求： /emp/12
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除操作",notes = "根据id删除员工")
    public AjaxResult delete(@PathVariable("id") Long id){

        //根据id区分,没有id就是新增
        try {
            //调用删除
            searchMasterMessageService.delete(id);

            return AjaxResult.createSuccess();
        } catch (Exception e) {

            e.printStackTrace();
            return AjaxResult.createError("操作异常,联系管理员李裕");
        }
    }
}
